(define (square-root x)
  (define (good-enough? guess next-guess tolerance)
    (< (/ (abs (- guess next-guess)) guess) tolerance))
  (define (improve guess)
    (average guess (/ x guess)))
  (define (square-root-iter guess)
    (define next-guess (improve guess))
    (if (good-enough? guess next-guess 0.001) guess
        (square-root-iter next-guess)))
  (square-root-iter 1.0))

(define (average x y)
  (/ (+ x y) 2))

(define (abs x)
  (if (< x 0) (- x) x))